import openai

openai.api_key = "sk-117hahihft1nkgc0t6qa5gvhd7q1mvndgcud046o3d4l6hm3",  # 你自己创建创建的Key
openai.api_base = "http://api.aihao123.cn/luomacode-api/open-api/v1"  # 你的base_url

competion = openai.ChatCompletion.create(
    model="gpt-4",
    messages=[
        {"role": "system", "content": "你是一个富有诗意的助手，擅长以创造性的天赋解释复杂的编程概念。"},
        {"role": "user", "content": "写一首诗来解释编程里面递归的概念。"},
    ],
    stream=True
)

# print(competion.choices[0].message)
# print(competion)
for chunk in competion:
    print(chunk.choices[0].delta.content, end="", flush=True)
